package net.huashitong.common.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.common.entity.SysMessageTemplate;
import net.huashitong.common.filter.SysMessageTemplateFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SysMessageTemplateDao extends StringDao<SysMessageTemplate> {
    public List<SysMessageTemplate> queryByFilter(SysMessageTemplateFilter filter) {
        GenericQuery query = createQuery("t");
        if (StringUtils.isNotBlank(filter.getTemplateType())){
            query.append(" AND t.templateType =:templateType").setParam("templateType",filter.getTemplateType());
        }
        if (StringUtils.isNotBlank(filter.getTemplateCode())){
            query.append(" AND t.templateCode =:templateCode").setParam("templateCode",filter.getTemplateCode());
        }
        if (StringUtils.isNotBlank(filter.getTemplateName())){
            query.append(" AND t.templateName like :templateName").setParam("templateName",StringUtils.getLikewords(filter.getTemplateName()));
        }
        if (StringUtils.isNotBlank(filter.getTemplateContent())){
            query.append(" AND t.templateContent like :templateContent").setParam("templateContent",StringUtils.getLikewords(filter.getTemplateContent()));
        }
        return query.listResult(filter);
    }
}
